package com.ruoyi.web.controller.tool;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysClient;
import com.ruoyi.system.service.ISysClientService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 终端信息Controller
 * 
 * @author spark
 * @date 2023-07-23
 */
@ApiOperation("终端信息管理")
@RestController
@RequestMapping("/test/client")
@Anonymous
public class TestClientController extends BaseController
{
    @Autowired
    private ISysClientService sysClientService;

    /**
     * 查询终端信息列表
     */
    @ApiOperation("查询终端信息列表")
    @GetMapping("/list")
    public TableDataInfo list(SysClient sysClient)
    {
        startPage();
        List<SysClient> list = sysClientService.selectSysClientList(sysClient);
        return getDataTable(list);
    }

    /**
     * 导出终端信息列表
     */
    @ApiOperation("导出终端信息列表")
    @Log(title = "终端信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysClient sysClient)
    {
        List<SysClient> list = sysClientService.selectSysClientList(sysClient);
        ExcelUtil<SysClient> util = new ExcelUtil<SysClient>(SysClient.class);
        util.exportExcel(response, list, "终端信息数据");
    }

    /**
     * 获取终端信息详细信息
     */
    @ApiOperation("获取终端信息详细信息")
    @GetMapping(value = "/{clientId}")
    public AjaxResult getInfo(@PathVariable("clientId") Long clientId)
    {
        return success(sysClientService.selectSysClientByClientId(clientId));
    }

    /**
     * 新增终端信息
     */
    @ApiOperation("新增终端信息")
    @Log(title = "终端信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysClient sysClient)
    {
        return toAjax(sysClientService.insertSysClient(sysClient));
    }

    /**
     * 修改终端信息
     */
    @ApiOperation("修改终端信息")
    @Log(title = "终端信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysClient sysClient)
    {
        return toAjax(sysClientService.updateSysClient(sysClient));
    }

    /**
     * 删除终端信息
     */
    @ApiOperation("删除终端信息")
    @Log(title = "终端信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clientIds}")
    public AjaxResult remove(@PathVariable Long[] clientIds)
    {
        return toAjax(sysClientService.deleteSysClientByClientIds(clientIds));
    }
}
